Appendix A. WinBUGS program for the latent basis model generated from BAUW
#model specification
model{
for (i in 1:N){
LS[i,1:2]~dmnorm(Mu[i,1:2], Inv_cov[1:2,1:2])
Mu[i,1]<-bL[1]
Mu[i,2]<-bS[1]
for (t in 1:T){
y[i,t]~dnorm(MuY[i,t], Inv_sig_e[t])
MuY[i,t]<-LS[i,1]+LS[i,2]*A[t]
}
}
#Prior distribution, can be changed to use informative prior
for (i in 1:1){
bL[i]~dnorm(0,1.0E-6)
bS[i]~dnorm(0,1.0E-6)
}
# the basis coefficients can be changed here.
A[1]<-0
for (t in 2:T-1){
A[t]~dnorm(0,1.0E-6)
}
A[T]<-1
Inv_cov[1:2,1:2]~dwish(R[1:2,1:2], 2)
R[1,1]<-1
R[2,2]<-1
R[2,1]<-R[1,2]
R[1,2]<-0
for (t in 1:T){
Inv_sig_e[t]~dgamma(.001,.001)
Sig_e[t]<-1/Inv_sig_e[t]
}
#Transform the parameters
Cov[1:2,1:2]<-inverse(Inv_cov[1:2,1:2])
Sig_L<-Cov[1,1]
Sig_S<-Cov[2,2]
rho<-Cov[1,2]/sqrt(Cov[1,1]*Cov[2,2])
#all parameter are put into
} #end of model part
#Starting values
#You can change the starting values by yourself here.
list(Inv_cov= structure(.Data = c(1,0,0,1),.Dim=c(2,2)), Inv_sig_e=c(1,1,1,1),
A=c(NA,0.333333,0.666667,NA),
bL=c(2),bS=c(3))
#Data
list(N=173,T=4,y = structure(.Data = c(2.6,4.9,5.5,7.2,
......